package Graph;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @author ZAY
 * 图的边类定义
 */
@Slf4j
@Data
public class Edge {
    /**
     * 很形象地表示一条边
     */
    private String edgeName;
    /**
     * 边的长度
     */
    private int length;
    /**
     * 边的起点
     */
    private Vertex startVertex;
    /**
     * 边的终点
     */
    private Vertex endVertex;
    public Edge(Vertex startVertex,Vertex endVertex){
        if (startVertex.getVertexName().equals(endVertex.getVertexName())){
            log.error("起点终点不能相同:"+this.edgeName);
            return;
        }
        this.startVertex = startVertex;
        this.endVertex = endVertex;
        // 默认长度为 10
        this.length = 10;
        this.edgeName = startVertex.getVertexName()+"--"+this.length+"-->"+endVertex.getVertexName();
    }
    public Edge(Vertex startVertex,Vertex endVertex,int length){
        if (startVertex.getVertexName().equals(endVertex.getVertexName())){
            log.error("起点终点不能相同");
            return;
        }
        this.startVertex = startVertex;
        this.endVertex = endVertex;
        // 默认长度为 10
        this.length = length;
        this.edgeName = startVertex.getVertexName()+"--"+this.length+"-->"+endVertex.getVertexName();
    }

    @Override
    public String toString() {
        return this.edgeName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Edge edge = (Edge) o;
        return edge.startVertex.equals(startVertex) && edge.endVertex.equals(endVertex);
    }

    @Override
    public int hashCode() {
        return Objects.hash(startVertex, endVertex);
    }
}
